package com.szzg10.thinking.chapter18;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Directory {

	public static void main(String[] args) {
		File file = new File("D:/workspace/szzg10/src");
		
		TreeInfo treeInfo = recuiseDirs(file);
		System.out.println(treeInfo.dirs);
		System.out.println(treeInfo.files);
	}
	
	public static TreeInfo recuiseDirs(File file) {
		TreeInfo treeInfo = new TreeInfo();
		
		File[] files = file.listFiles();
		for(File element: files) {
			if(element.isDirectory()) {
				treeInfo.addDir(element);
				treeInfo.addAll(recuiseDirs(element));
			}
			else {
				treeInfo.addFile(element);
			}
		}
		
		return treeInfo;
	}
}

class TreeInfo {
	public List<File> dirs = new ArrayList<File>();
	public List<File> files = new ArrayList<File>();
	
	public void addDir(File dir) {
		dirs.add(dir);
	}
	
	public void addFile(File file) {
		files.add(file);
	}
	
	public void addAll(TreeInfo treeInfo) {
		dirs.addAll(treeInfo.dirs);
		files.addAll(treeInfo.files);
	}
}